/***************************************************************************
 *  Filename: mainloopfunctions.h
 *  Class: MainLoopFunctions
 *  
 *  Copyright 2012  Jacco van der Spek
 *  <jaccovdspek@gmail.com>
 *
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/

/*
 *
 * This file is part of %ProjectName%.
 *
 *    %ProjectName% is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    %ProjectName% is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with %ProjectName%.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MAINLOOPFUNCTIONS_H
#define MAINLOOPFUNCTIONS_H

#include <QObject>
#include <QList>
#include <QTime>

//Own libraries
#include <barohandler.h>
#include <gpshandler.h>
#include <parrothandler.h>
#include <groundscommunicator.h>
#include <videoprocessing.h>
//Own data types
#include <flightdata.h>
#include <gpsdata.h>




class MainLoopFunctions : public QObject
{
    Q_OBJECT
public:
    explicit MainLoopFunctions(BaroHandler *tbarometer,
                               GPSHandler *tgpshandler,
                               ParrotHandler *tparrothandler,
                               GroundSCommunicator *txbee,
                               VideoProcessing *tvideo,
                               QObject *parent = 0);
    void startPictureTimer(int s);
    void startSenderTimer(int ms);
    void startMainLoopTimer(int ms);
signals:
    
public slots:
    void run();
    void init();
private:
    BaroHandler *barometer;
    GPSHandler *gps;
    ParrotHandler *parrot;
    GroundSCommunicator *xbee;
    VideoProcessing *video;

    QTimer timer;
    QTimer pictureTakeTimer;
    QTimer senderTimer;

    // Flight data
    FlightData uavData;
    GPSData carData;
    // Time-out functions
    QTime gpsTimeKeeper;
    QTime baroTimeKeeper;
    QTime arDroneTimeKeeper;

private slots:
    void updateParrotAltitude(int alt);
    void updateParrotAngles(float roll, float pitch, float yaw);
    void updateParrotBattery(int battery);
    void updateParrotVelocities(float vx, float vy, float vz);
    void sendFlightData();
};

#endif // MAINLOOPFUNCTIONS_H
